// utils/cloud.js
const cloud = wx.cloud

// 初始化云开发
const initCloud = () => {
  if (!cloud.init()) {
    console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    return false
  }
  return true
}

// 上传文件
const uploadFile = (cloudPath, filePath) => {
  return new Promise((resolve, reject) => {
    cloud.uploadFile({
      cloudPath,
      filePath,
      success: resolve,
      fail: reject
    })
  })
}

// 删除文件
const deleteFile = (fileList) => {
  return new Promise((resolve, reject) => {
    cloud.deleteFile({
      fileList,
      success: resolve,
      fail: reject
    })
  })
}

// 获取临时链接
const getTempFileURL = (fileList) => {
  return new Promise((resolve, reject) => {
    cloud.getTempFileURL({
      fileList,
      success: resolve,
      fail: reject
    })
  })
}

module.exports = {
  initCloud,
  uploadFile,
  deleteFile,
  getTempFileURL
}